package
{
	import de.polygonal.math.PM_PRNG;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;
	import flash.utils.getTimer;
	
	public class fun extends Sprite
	{
		public function fun()
		{
			var world:World;
			var bot:Bot;
			
			stage.frameRate = 30;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
			
			Global.PPU = 4;
			Global.LAST_TIME = Global.CURRENT_TIME = getTimer();
			Global.PRNG = new PM_PRNG();
			Global.PRNG.seed = 1;
	
			world = new World();
			world.size = new Point(200,200);
			world.initialize();
//			var worldGenTimer:Timer = new Timer(250);
//			worldGenTimer.addEventListener(TimerEvent.TIMER, function(te:TimerEvent):void{
//				world.genRandomObstacle();
//			});
//			var i:int = 0;
//			stage.addEventListener(MouseEvent.CLICK, function(me:MouseEvent):void{
//				trace("Adding" + i++);
//				world.genRandomObstacle();
//				
//			});
			
			world.generateRandomObstacles();
			var timer:Timer = new Timer(250);
			var i:int = 1;
			timer.addEventListener(TimerEvent.TIMER, function(te:TimerEvent):void{
				world.addBot(10);
				//world.addBot(i*20);

				if(++i > 10) timer.stop();
				
			});
			timer.start();
			
			Global.WORLD_RECT = world.getRect();
			
			stage.addEventListener(Event.ENTER_FRAME, function(e:Event):void{
				Global.CURRENT_TIME = getTimer();
				Global.DELTA_TIME = Global.CURRENT_TIME - Global.LAST_TIME;
				world.update();
				Global.LAST_TIME = Global.CURRENT_TIME;
			});
			
			
			
			addChild(world.display);
			Util.center(world.display);
		}
	}
}